package com.atguigu.tingshu.user.foctory.impl;

import com.atguigu.tingshu.user.foctory.StrategyFactory;
import com.atguigu.tingshu.user.strategy.ItemTypeStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class StrategyFactoryImpl implements StrategyFactory {

    /**
     * 将IOC容器中ItemTypeStrategy接口下的所有实现类注入到Map中
     * Map中Key：Bean对象Id
     * Map中Value：实现类对象
     * {"1001":购买类型为专辑策略类对象}
     * {"1002":购买类型为声音策略类对象}
     * {"1003":购买类型为会员策略类对象}
     */
    @Autowired
    private Map<String,ItemTypeStrategy> strategyMap;

    @Override
    public ItemTypeStrategy getStrategy(String key) {
        //获取到对应的策略类
        if (strategyMap.containsKey(key)){
            //获取到对应的策略
            return strategyMap.get(key);
        }
        return null;
    }
}
